pp108 : XML changes for Multi-browser Support

XML changes for Multi-browser Support

This topic describes the changes required in XML content of an application to enable multi-browser support.

The XML content in an application must be made standards compliant to enable multi-browser support.

Requesting XML Object through XML HTTP

Different browsers require different implementations of XMLHTTP for requesting an XML object. To make it Standards complaint, Process Platform provides a standard API to call theActiveXObject()method, so that the application need not be hard coded by users for supporting various browsers.

As an example consider the following sample codes,

Old Usage: Standards non-compliant sample code in Quirks Mode var myConnection = new ActiveXObject("Microsoft.XMLHTTP");
New Usage: Standards compliant sample code in Transitional Mode var myConnection = cordys.getConnection();

XML Content in the <head> Tag

XML Web content (data islands) in the<head>sections of the an application do not render properly with all browsers. To resolve this, a new type namespace is introduced that wraps XML islands with a <script> tag.

As an example, consider the following sample code,

Old Usage: Standards non-compliant sample code in Quirks Mode <xml id="applicationmanager"> <Application toolbar="true"> <icon>images/applicationmanager.gif</icon> <url>debugger/applicationmanager.htm</url> <id>ApplicationManager</id> <description>ApplicationManager</description> <caption>ApplicationManager</caption> <frame>headerToolbar</frame> </Application> </xml>
New Usage: Standards compliant sample code in Transitional Mode <script type="cordys/xml" id="applicationmanager"> <Application toolbar="true"> <icon>images/applicationmanager.gif</icon> <url>debugger/applicationmanager.htm</url> <id>ApplicationManager</id> <description>ApplicationManager</description> <caption>ApplicationManager</caption> <frame>headerToolbar</frame> </Application> </script>

Note: In the above example, the wrapper object represented by "id", displays only after the page has been loaded. Due to this, it is not possible to use the XML document in the global JavaScript code that is executed when a Web page is loaded.

The Standards-compliant code is converted to a valid XML document by all browsers that can be accessed by XMLDocument, and is available for use as required.
Consider the following sample code for accessing an XML document in an application or form,

Old Usage: Standards non-compliant sample code in Quirks Mode var sampleXMLObject = applicationmanager;
New Usage: Standards compliant sample code in Transitional Mode var sampleXMLObject = applicationmanager.XMLDocument;

No Support for src Attribute

The src attribute is not supported by all browsers. Alternatively, use the load() method of XML Document to load XML from a URL.

Note:
Process Platform XForms automatically generates XML in this format when HTML is rendered at runtime.

Usage of .documentElement and .xml properties

The .xml property that is used to serialize an XML node is supported by the Internet Explorer browser only. To make it Standards compliant, a new wrapper,cordys.getXML(), is introduced to serialize XML into a string. The .documentElement property must be used only on the XMLDocument and not on the wrapper object itself.

Consider the following sample code,

Old Usage: Standards non-compliant sample code in Quirks Mode var documentElement = myXML.documentElement; var xml = myXML.xml;
New Usage: Standards compliant sample code in Transitional Mode var documentElement = myXML.XMLDocument.documentElement; var xml = cordys.getXML(myXML.XMLDocument);

Comments in XML Dataisland

Comments on an XML data island must be placed inside the XML and not between the<script>and the first<xml>tags, otherwise the comment will be considered as part of the XMLDocument. Also, the <script type="cordys/xml"> tag must contain a single child tag.

Consider the following sample code,

Old Usage: Standards non-compliant sample code in Quirks Mode <script type="cordys/xml" id="someXML"> <!-- This is some comment which should not be placed here --> <someXML> </someXML> </script>
New Usage: Standards compliant sample code in Transitional Mode <script type="cordys/xml" id="someXML"> <someXML> <!-- comment is allowed here--> </someXML> </script>

XML Document Manipulations

For creating, loading, cloning, appending, and selecting XML documents, Process Platform provides wrapper APIs that must be used on top of the XML. For information about the APIs, see cordys.

The attributes of an XML document can be accessed only as an array on multi-browsers, and cannot be used to iterate through the collection (this is supported only by the Internet Explorer browser).

Consider the following sample code,

Old Usage: Standards non-compliant sample code in Quirks Mode var attributes = xmlNode.attributes; for ( var I = 0, length = attributes.length; I < length; I++ ) { var attribute = attributes[i]; ... }
New Usage: Standards compliant sample code in Transitional Mode var attributes = xmlNode.attributes; for (var attribute = attributes.nextNode(); attribute ;attribute = attributes.nextNode()) { ... }

XPATH Expressions

When using the selectSingleNode() and selectNodes() methods to search an XML document, the use ofXSLPatternis not supported by multiple browsers. To ensure multi-browser support, use XPath instead.

Consider the following sample code. Here, <key> is associated with the http//schemas.cordys.com/1.1/ldap namespace. While using XPath, the selection criteria must be set as .//ldap:key, but the Internet Explorer browser ignores the namespace and the .//key expression.

Old Usage: Standards non-compliant sample code in Quirks Mode <xml id="requestGetUserDetails"> <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetUserDetails xmlns="http://schemas.cordys.com/1.1/ldap"> <key>userfound</key> </GetUserDetails> </SOAP:Body> </SOAP:Envelope> </xml> var request = requestGetUserDetails.XMLDocument.documentElement; var key = request.selectNodes(".//key"); var envelope = request.selectNodes(".//ancestor(SOAP:Body)");
New Usage: Standards compliant sample code in Transitional Mode <script type="cordys/xml"> <xml id="requestGetUserDetails"> <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetUserDetails xmlns="http://schemas.cordys.com/1.1/ldap"> <key>userfound</key> </GetUserDetails> </SOAP:Body> </SOAP:Envelope> </xml> </script> var request = requestGetUserDetails.XMLDocument.documentElement; var ownerDocument = request.ownerDocument; cordys.setXMLNamespaces(ownerDocument, {"ldap":"http://schemas.cordys.com/1.1/ldap", "SOAP":"http://schemas.xmlsoap.org/soap/envelope/"} ); var key = cordys.selectXMLNodes(request,".//ldap:key"); var envelope= cordys.selectXMLNodes(request,".//ancestor::SOAP:Body");

In some cases, it may be required to select a node with a specific tagName, without knowing if a (default) namespace is defined in the XMLDocument. For example, an the Application Definition can be of a local XML Dataisland on the Web page without a namespace, or a document from the XML store withxmlstoreas its default namespace. As an alternative to ignoring namespaces in the XPath query language, you can use the local-name() method in your XPath query.

As an example, consider the following sample code. The sample code returns the 'frame' element regardless of the namespace it may be associated with.

Old Usage: Standards non-compliant sample code in Quirks Mode cordys.setXMLNamespaces(dataNode.ownerDocument, { "xs":"http://schemas.cordys.com/1.0/xmlstore" } ); var frameNode = cordys.selectXMLNode(applicationDefinition,"xs:frame");
New Usage: Standards compliant sample code in Transitional Mode var frameNode = cordys.selectXMLNode(applicationDefinition,"*[local-name()='frame']");

You can learn more about the XPath syntax at http://www.w3schools.com/xpath.